/**
 * @param {object} x
 * @return {number} 
 */

function cakes(recipe, available) {
  var rec = Object.getOwnPropertyNames(recipe)
  var ava = Object.getOwnPropertyNames(available)
  var flag = true
  var num = 1
  for (let i = 0; i < rec.length; i++) {
    if (recipe[rec[i]] == 0) return 0
    tp = ava.indexOf(rec[i])
    if (tp == -1) return 0
    if (available[ava[tp]] / recipe[rec[i]] < 1) return 0
    if (flag) {
      num = available[ava[tp]] / recipe[rec[i]]
      flag = false
    }
    if (available[ava[tp]] / recipe[rec[i]] < num) { num = available[ava[tp]] / recipe[rec[i]] }
  }
  return Math.floor(num)
}

function cakes(recipe, available) {
  return Object.keys(recipe).reduce(function (val, ingredient) {
    return Math.min(Math.floor(available[ingredient] / recipe[ingredient] || 0), val)
  }, Infinity)
}


const cakes = (needs, has) => Math.min(
  ...Object.keys(needs).map(key => Math.floor(has[key] / needs[key] || 0))
)

function cakes(recipe, available) {
  var numCakes = [];

  for (var key in recipe) {
    if (recipe.hasOwnProperty(key)) {
      if (key in available) {
        numCakes.push(Math.floor(available[key] / recipe[key]));
      } else {
        return 0;
      }
    }
  }
  return Math.min.apply(null, numCakes);
}

function cakes(recipe, available) {
  return Math.min(...Object.keys(recipe).map(e => available[e] / recipe[e] >> 0));
}

function cakes(recipe, supplies) {
  var n = [];
  for (var key in recipe)
    if (key in supplies)
      n.push(Math.floor(supplies[key] / recipe[key]));
    else
      return 0;
  return Math.min.apply(Math, n);
}


console.log(cakes({ "crumbles": 0, "pears": 51, "butter": 6 }, { "oil": 2100, "nuts": 2700, "flour": 8300, "pears": 1300, "eggs": 2700, "chocolate": 2400, "cocoa": 1800, "apples": 3900, "crumbles": 2800, "milk": 5900, "cream": 6400, "sugar": 8500, "butter": 6100 }));